package com.cloud.logger.zchain.zchainserver.controller;

import com.cloud.logger.zchain.zchainserver.entity.AngelaLoggerProject;
import com.cloud.logger.zchain.zchainserver.entity.vo.AngelaLoggerProjectBugVo;
import com.cloud.logger.zchain.zchainserver.entity.vo.AxisVo;
import com.cloud.logger.zchain.zchainserver.mongo.AngelaEntityRepository;
import com.cloud.logger.zchain.zchainserver.mongo.AngelaProjectNodeRepository;
import com.cloud.logger.zchain.zchainserver.mongo.AngelaProjectRepository;
import com.cloud.logger.zchain.zchainserver.service.AngelaPjMonthAdWeekService;
import com.cloud.logger.zchain.zchainserver.service.MainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * User: wcy
 * Date: 2017/11/29
 * Time: 15:53
 */
@RestController
@RequestMapping(value = "main")
@Api(value = "/主界面", description = "主界面接口")
public class MainCtl {

    private static String START_TIME= " 00:00:01";

    @Resource
    private AngelaProjectRepository angelaProjectRepository;

    @Resource
    private AngelaProjectNodeRepository angelaProjectNodeRepository;

    @Resource
    private AngelaEntityRepository angelaEntityRepository;

    @Resource
    private AngelaPjMonthAdWeekService angelaPjMonthAdWeekService;

    @Resource
    private MainService mainService;

    @GetMapping(value = "findCompany")
    @ApiOperation(value = "获取左边所有合作单位导航栏数据")
    public List<AngelaLoggerProject> findCompany(){
        return mainService.findCompany();
    }

    @GetMapping(value = "findProject/{id}")
    @ApiOperation(value = "获取左边所有项目导航栏数据")
    public List<AngelaLoggerProjectBugVo> findProjectTree(@PathVariable(value = "id") String id){
         return mainService.findProjectTree(id);
    }

    @GetMapping(value = "findAnalysisBugs/{id}/{type}")
    @ApiOperation(value = "获取今日（type:day），七天（type:week），一个月（type:month）bug数  -by zhengyt")
    public AxisVo findLastWeekOrMonthBugs(@PathVariable(value = "id") String id,@PathVariable(value = "type") String type) throws Exception {
        if("day".equals(type))
            return angelaPjMonthAdWeekService.findTodayBugs(id);
        else
            return angelaPjMonthAdWeekService.findLastWeekOrMonthBugs(id, type);
    }


}


